package com.potter.provision

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.JavascriptInterface
import android.webkit.WebView
import androidx.fragment.app.Fragment
import com.fenbi.android.ytkjsbridge.addYTKJavascriptInterface
import com.fenbi.android.ytkjsbridge.debugMode
import com.fenbi.android.ytkjsbridge.initYTKJsBridge
import com.wkm.myapplication.R

class WebViewFragment : Fragment() {

    companion object {
        private const val TAG = "WebViewFragment"
        const val KEY_POLICY_URL = "policy_url"

        /** 用户注册协议地址 */
        const val USER_REGISTRY_POLICY_URL =
            "https://conan.yuanfudao.com/webapp/conan-webapp-user-agreement/latest/detail.html?isFullScreen=true&hideNavigation=true&disableHdFeature=true&pageType=1&hideNavigationForPad=false&title=%E7%94%A8%E6%88%B7%E6%B3%A8%E5%86%8C%E5%8D%8F%E8%AE%AE"

        /** 用户隐私协议地址 */
        const val USER_PRIVACY_POLICY_URL =
            "https://conan.yuanfudao.com/webapp/conan-webapp-user-agreement/latest/detail.html?isFullScreen=true&hideNavigation=true&disableHdFeature=true&pageType=2&hideNavigationForPad=false&title=%E7%94%A8%E6%88%B7%E9%9A%90%E7%A7%81%E5%8D%8F%E8%AE%AE"

        /** 儿童隐私协议地址 */
        const val CHILD_PRIVACY_POLICY_URL =
            "https://conan.yuanfudao.com/webapp/conan-webapp-user-agreement/latest/detail.html?isFullScreen=true&hideNavigation=true&disableHdFeature=true&pageType=3&hideNavigationForPad=false&title=%E5%84%BF%E7%AB%A5%E9%9A%90%E7%A7%81%E4%BF%9D%E6%8A%A4%E6%94%BF%E7%AD%96"

    }

    private var onBackPressListener: (() -> Unit)? = null

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.potter_fragment_web, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val webview: WebView = view.findViewById(R.id.webview)
        webview.initYTKJsBridge()
        webview.loadUrl(USER_REGISTRY_POLICY_URL)
        webview.addYTKJavascriptInterface(WebAppApi)
    }

}


object WebAppApi {
    @JavascriptInterface
    fun f() {
        Log.e("TAG", "fff")
    }
}